package com.leo.oplayer.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.leo.oplayer.R;
import com.leo.oplayer.model.WhitePerson;
import com.leo.oplayer.util.PersonUtil;

public class WhitePersonAdapter extends ArrayAdapter<WhitePerson>{

	int resource;

	public WhitePersonAdapter(Context _context, int _resource,List<WhitePerson> _items) {
		super(_context, _resource, _items);
		this.resource = _resource;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) 
	{
		LinearLayout todoView; 
		WhitePerson white = getItem(position); 
		String personId = white.getPersonId();
		String personName = PersonUtil.findNameById(getContext(), personId);
		
		
		if (convertView == null) 
		{ 
			todoView = new LinearLayout(getContext()); 
			String inflater = Context.LAYOUT_INFLATER_SERVICE; 
			LayoutInflater vi; 
			vi = (LayoutInflater)getContext().getSystemService(inflater);
			vi.inflate(resource, todoView, true); 
		} 
		else { 
			todoView = (LinearLayout) convertView;
		} 
		TextView personIdView = (TextView)todoView.findViewById (R.id.white_person_id); 
		TextView nameView = (TextView)todoView.findViewById (R.id.white_person_name); 
	
		personIdView.setText(personId);
		nameView.setText(personName);
		
		return todoView; 
	}
	
	
}
